package com.sline.collection;

import com.sline.bean.Student;

import java.util.ArrayList;
import java.util.Collection;

public class Demo2_Collection {
    public static void main(String[] args) {
        // demo1();

        Collection c = new ArrayList();
        c.add("a");
        c.add("b");
        c.add("c");
        c.add("a");

        // 移除一个元素
        c.remove("b");
        System.out.println(c);
        c.remove("a");
        System.out.println(c);

        // 判断是否包含
        System.out.println("是否包含a: " + c.contains("a"));

        // 判断是否为空数组
        System.out.println(c.isEmpty());

        // 获取元素的个数
        System.out.println(c.size());

        // 清空数组
        c.clear();
        System.out.println(c);

        System.out.println(c.isEmpty());
    }

    private static void demo1() {
        Collection c = new ArrayList();
        boolean b1 = c.add("abc");
        boolean b2 = c.add(true);
        boolean b3 = c.add(100);
        boolean b4 = c.add(new Student());
        System.out.println(b1);
        System.out.println(b2);
        System.out.println(b3);
        System.out.println(b4);
        System.out.println(c);
    }
}
